<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\AppUpgrade;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Support\Facades\Cache;

class AppUpgradeController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new AppUpgrade(), function (Grid $grid) {
            $grid->model()->orderByDesc('id');
//            $grid->column('app_type')->using(['ios'=>'IOS','android'=>'Android']);
            $grid->column('app_title');
            $grid->column('app_v');
            $grid->column('app_desc');
            $grid->column('url');
//            $grid->column('cur_type','类型')->using([1=>'普通包',2=>'热更包']);
            $grid->column('upgrade_way')->using([1=>'强制升级',2=>'正常关闭']);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
            $grid->disableRowSelector();
            //禁用新增按钮
//            $grid->disableCreateButton();
            // 禁用过滤器按钮
            $grid->disableFilterButton();
            // 禁用批量删除按钮
            $grid->disableBatchDelete();
            // 禁用显示按钮
            $grid->disableViewButton();
            // 去掉删除
            $grid->disableDeleteButton();
            //显示横向滚动条
            $grid->scrollbarX();
        });
    }


    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new AppUpgrade(), function (Form $form) {
            $form->display('id');
//            $form->select('app_type')->options(['ios'=>'IOS','android'=>'Android'])->default('android');
            $form->text('app_title');
            $form->text('app_v');
            $form->textarea('app_desc');
//            $form->text('url','下载地址')->required();
            $form->file('url')->removable(false)->downloadable()->retainable()
                ->accept('apk')
                ->saveFullUrl(true)
                ->move('download')
                ->maxSize(1024 * 100)->required();
//            $form->select('cur_type','类型')->options([1=>'普通包',2=>'热更包']);
            $form->select('upgrade_way')->options([1=>'强制升级',2=>'正常关闭'])->default(1);
            $form->display('created_at');
            $form->display('updated_at');
            $form->saved(function () {
                Cache::forget('add-update-android');
                Cache::forget('add-update-android-hot');
            });
            // 去掉`重置`按钮
            $form->disableResetButton();
            // 去掉`查看`checkbox
            $form->disableViewCheck();
            // 去掉`继续编辑`checkbox
            $form->disableEditingCheck();
            $form->disableDeleteButton();
            $form->disableViewButton();
            // 去掉`继续创建`checkbox
            $form->disableCreatingCheck();
        });
    }
}
